package com.study.aop.theory.myaopdemo;

import com.study.aop.theory.myaop.Advice;

import java.lang.reflect.Method;

/**
 * AOP增强种类有：
 * 1、前置增强
 * 2、后置增强
 * 3、环绕增强
 * 4、异常增强
 *
 * @author: chenhs
 * @date: Created in 14:55 2019/12/8
 **/
public class TimeCsAdvice implements Advice {
    @Override
    public Object invoke(Object target, Method method, Object[] args) throws Exception {

        long stime = System.currentTimeMillis();
        //执行业务方法
        Object ret = method.invoke(target, args);

        long useTime = System.currentTimeMillis() - stime;

        System.out.println("记录：" + target.getClass().getName() + "." + method.getName() + " 耗时：" + (useTime / 1000) + " 秒");

        return ret;
    }
}
